from web import creat_app
from web.model.base_model import db
from web.model.user_model import Admin
from web.control.error.error_code import Success, SQLException
app = creat_app()


@app.route('/superadmin/', methods=['POST'])
def creat_super():
    root = Admin.query.filter(Admin.adminAccount == 'superadmin').first()
    try:
        if not root:
            admin = Admin()
            admin.adminAccount = 'superadmin'
            admin.passWord = 'superadmin'
            db.session.add(admin)
            db.session.commit()
    except Exception as e:
        return SQLException(msg=e)
    return Success(msg="创建数据成功")


if __name__ == '__main__':
    app.run(debug=app.config['DEBUG'], host='0.0.0.0')
